package me.sdevil507.org.controller;

import lombok.extern.slf4j.Slf4j;
import me.sdevil507.supports.result.ApiResultDTO;
import me.sdevil507.supports.result.ApiResultGenerator;
import me.sdevil507.supports.status.ApiStatusCode;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 安全退出操作
 *
 * @author sdevil507
 * @version 1.0
 */
@RestController
@RequestMapping("/api/org/user")
@Slf4j
public class OrgUserLogoutController {

    /**
     * 执行安全退出操作
     *
     * @return 执行反馈
     */
    @PostMapping(value = "/logout")
    public ApiResultDTO logout() {
        ApiResultDTO apiResultDTO = null;
        Subject subject = SecurityUtils.getSubject();
        if (null != subject.getPrincipal()) {
            if (subject.isAuthenticated()) {
                //如果是登录状态,执行安全退出
                subject.logout();
                apiResultDTO = ApiResultGenerator.create(ApiStatusCode.SUCCESS.getCode(), ApiStatusCode.SUCCESS.getDescription());
            }
        }
        return apiResultDTO;
    }

}
